<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "order_info".
 *
 * @property int $id
 * @property int $relate_id 退款订单关联的支付订单id
 * @property int $user_id 用户id
 * @property int $order_type 订单类型(1:支付订单 2:退款订单)
 * @property string $order_sn 订单号
 * @property string $money_origin 订单原始金额
 * @property string $money_discount 订单优惠金额
 * @property string $money 订单商品应付金额
 * @property int $pay_at 支付时间
 * @property int $state 订单状态(0：待支付 1：待发货 2：待收货 3：售后中 4：订单完成 5：退款中 6：退款成功 7：退款失败  8：已取消)
 * @property int $refund_state 退款审核状态(0:待审 1:通过 2:拒绝)
 * @property string $refund_reason 退款申请理由
 * @property string $refund_imgs 退款申请图片
 * @property string $audit_reason 退款审核理由
 * @property int $audit_user_id 退款审核人
 * @property int $status 状态
 * @property string $remark 订单备注
 * @property string $mch_id 微信商户号
 * @property string $mch_key 微信商户key
 * @property int $address_id 收货人地址id
 * @property string $order_send_name 快递商名称
 * @property string $order_send_code 快递单号
 * @property int $send_at 发货时间
 * @property int $receive_at 收货时间
 * @property int $refund_start_at 发起退款时间
 * @property int $refund_success_at 退款成功时间
 * @property int $created_at 创建时间
 */
class OrderInfo extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'order_info';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['relate_id', 'user_id', 'order_type', 'pay_type', 'send_type', 'pay_at', 'state', 'refund_state', 'audit_user_id', 'status', 'address_id', 'send_at', 'receive_at', 'refund_start_at', 'refund_success_at', 'created_at'], 'integer'],
            [['money_origin', 'money_discount', 'money'], 'number'],
            [['refund_reason', 'refund_imgs', 'audit_reason'], 'string'],
            [['order_sn', 'remark', 'mch_id', 'mch_key', 'order_send_name', 'order_send_code'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'relate_id' => 'Relate ID',
            'user_id' => 'User ID',
            'order_type' => 'Order Type',
            'order_sn' => 'Order Sn',
            'money_origin' => 'Money Origin',
            'money_discount' => 'Money Discount',
            'money' => 'Money',
            'pay_type' => 'Pay Type',
            'pay_at' => 'Pay At',
            'state' => 'State',
            'refund_state' => 'Refund State',
            'refund_reason' => 'Refund Reason',
            'refund_imgs' => 'Refund Imgs',
            'audit_reason' => 'Audit Reason',
            'audit_user_id' => 'Audit User ID',
            'status' => 'Status',
            'remark' => 'Remark',
            'mch_id' => 'Mch ID',
            'mch_key' => 'Mch Key',
            'address_id' => 'Address ID',
            'order_send_name' => 'Order Send Name',
            'order_send_code' => 'Order Send Code',
            'send_at' => 'Send At',
            'receive_at' => 'Receive At',
            'refund_start_at' => 'Refund Start At',
            'refund_success_at' => 'Refund Success At',
            'created_at' => 'Created At',
        ];
    }

    public function getUser(){
      return $this->hasOne(User::class, ['id' => 'user_id']);
    }

    public function getOrder(){
      return $this->hasOne(OrderInfo::class, ['id' => 'relate_id']);
    }

    public function getAddress(){
      return $this->hasOne(Address::class, ['id' => 'address_id']);
    }

    public function getAuditUser(){
      return $this->hasOne(Admin::class, ['id' => 'audit_user_id']);
    }
}
